package com.changyinBus.common.core.domain.entity;

import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.changyinBus.common.core.domain.BaseEntity;
import com.changyinBus.common.utils.IDGenerator;
import lombok.Data;

import java.util.Date;

@Data
public class SysArticle extends BaseEntity {
    @JsonSerialize(using = ToStringSerializer.class)
    private Long articleId;
    @JsonSerialize(using = ToStringSerializer.class)
    private Long cateId;
    private int typeId;
    /**
     * 祖级列表
     */
    private String ancestors;
    //文章分类:1资讯
    private int articleType;
    private String title;
    private String subTitle;
    //发布时间
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private Date publishDate;
    private String headTitle;
    //作者
    private String author;
    //来源
    private String source;
    //是否外链
    private String isLink;
    //外链地址
    private String linkUrl;
    //信息摘要
    private String intro;
    //封面图片
    private String images;
    //内容
    private String content;

    public JSONObject contentJson;

    //附件地址
    private String attachment;
    //置顶显示图片
    private String isTop;
    //排序序号
    private Integer sort;
    //状态0正常1停用
    private String status;
    /**
     * 租户ID
     */
    private long tenantId;
    //删除标志（0代表存在 2代表删除）
    private Integer delFlag;

    private String createBy;
    private Long createId;
    private Date createTime;
    private String updateBy;
    private Long updateId;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    public SysArticle(){}

    public SysArticle(SysArticle article){
        this.articleId = IDGenerator.getID();
        this.setParam(article);

    }

    public void setParam(SysArticle article){
        this.cateId = article.getCateId();
        this.typeId = article.getTypeId();
        this.ancestors = article.getAncestors();
        this.articleType = article.getArticleType();
        this.title = article.getTitle();
        this.subTitle = article.getSubTitle();
        this.publishDate = article.getPublishDate();
        this.headTitle = article.getHeadTitle();
        this.author = article.getAuthor();
        this.source = article.getSource();
        this.isLink = article.getIsLink();
        this.linkUrl = article.getLinkUrl();
        this.intro = article.getIntro();
        this.images = article.getImages();
        this.content = article.getContent();
        this.attachment = article.getAttachment();
        this.isTop = article.getIsTop();
        this.sort = article.getSort();
        this.status = article.getStatus();
        this.tenantId = article.getTenantId();
        this.delFlag = article.getDelFlag();
    }

    public void setContentJson(JSONObject contentJson){
        this.contentJson = contentJson;
    }

    public JSONObject getContentJson(){
        try{
            return JSONObject.parseObject(content);
        }catch(Exception e){
            return new JSONObject();
        }
    }

}
